package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespData;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.pojo.Comment;
import com.cskaoyan.service.admin.CommentService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname CommentController
 * @Description
 * @Date 2021/8/12 19:48
 * @Author : xujun
 */
@RestController
@RequestMapping("admin/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    /**
     * 删除评论，逻辑删除，deleted: false -> true
     * @param comment
     * @return
     */
    @RequiresPermissions(value = {"*", "admin:comment:delete"}, logical = Logical.OR)
    @PostMapping("delete")
    public BaseRespVo commentDelete(@RequestBody Comment comment) {

        // 逻辑删除
        comment.setDeleted(true);
        // 更新(删除)评论
        commentService.commentDelete(comment);

        return BaseRespVo.ok();
    }

    /**
     * 展示评论
     * @param valueId
     * @param userId
     * @param bo
     * @return
     */
    @RequiresPermissions(value = {"*", "admin:comment:list"}, logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo commentList(Integer valueId, Integer userId, BaseParam bo) {

        BaseRespData baseRespData = commentService.commentList(valueId, userId, bo);

        return BaseRespVo.ok(baseRespData);
    }

}
